package br.com.pucrs.tcc.controller;

import java.io.Serializable;
import java.util.ArrayList;

import javax.annotation.PostConstruct;
import javax.ejb.EJB;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.ViewScoped;

import org.primefaces.model.DefaultScheduleEvent;
import org.primefaces.model.DefaultScheduleModel;
import org.primefaces.model.ScheduleEvent;
import org.primefaces.model.ScheduleModel;

import br.com.pucrs.tcc.ed.Evento;
import br.com.pucrs.tcc.rn.EventoRN;
import br.com.pucrs.tcc.util.jsf.SessionUtil;

@ManagedBean(name = "EventoAgendaBean")
@ViewScoped
public class EventoAgendaBean implements Serializable {

	@EJB
	private EventoRN mEventoRN;
	
	private ScheduleModel eventModel;

	private ScheduleEvent event;

	private ArrayList<Evento> eventos; 
	
	public EventoAgendaBean() {
		event = new DefaultScheduleEvent();
		eventModel = new DefaultScheduleModel();
		eventos = new ArrayList<Evento>();
	}

	@PostConstruct
	public void carregaDados() {
		eventos = (ArrayList<Evento>) mEventoRN.listarEventos(SessionUtil.getMatriculaUsuarioLogado());
		
		for (Evento e : eventos) {
			eventModel.addEvent(new DefaultScheduleEvent(e.getTitulo(), e.getDthEvento(), e.getDthEvento()));
		}
	}

	public ScheduleModel getEventModel() {
		return eventModel;
	}

	public ScheduleEvent getEvent() {
		return event;
	}

	public void setEvent(ScheduleEvent event) {
		this.event = event;
	}

}
